/************************************************/
/************************************************/
/**** PART 3.1: MAIN PAPER FIGURE 1 ****/
/************************************************/
/************************************************/

*** test of equality of distributions	
	
	preserve

	collapse (max) bcoleman_ref*  maleshare  biat_ethnic  baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured bteyes_sd btraven_sd b_pedagogy b_gms b_idealism b_competence b_modern b_extrinsic b_warmth csize gr1 gr2 grade1 b_schoolid b_classid baseline_tterm urfa refshare b_districtid btsurvey_16_refprop sample1 sample0 bexper empathy_treatment ref_exposure (mean) male ageinm braven_sd bmath_std bturk_std, by(btname)
	replace ref_exposure=4 if ref_exposure>4 & ref_exposure<.
	keep if sample1==1 |sample0==1
	tab ref_exposure, gen(refexp)

	ksmirnov biat_ethnic if refexp1==1 | refexp2==1, by(refexp1)
	local p1 : display %5.2f = r(p)		
	ksmirnov biat_ethnic if refexp2==1 | refexp3==1, by(refexp2)
	local p2 : display %5.2f = r(p)			
	ksmirnov biat_ethnic if refexp3==1 | refexp4==1, by(refexp3)
	local p3 : display %5.2f = r(p)				   	   
	ksmirnov biat_ethnic if refexp4==1 | refexp5==1, by(refexp4)
	local p4 : display %5.2f = r(p)		

	restore


*** Refugee exposure and Teacher Ethnic Bias	

	tempfile teacher_data
	save `teacher_data'

	collapse (max) bcoleman_ref*  maleshare  biat_ethnic  baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured bteyes_sd btraven_sd b_pedagogy b_gms b_idealism b_competence b_modern b_extrinsic b_warmth csize gr1 gr2 grade1 b_schoolid b_classid baseline_tterm urfa refshare b_districtid btsurvey_16_refprop sample1 sample0 bexper empathy_treatment ref_exposure (mean) male ageinm braven_sd bmath_std bturk_std, by(btname)

	** winsorize ref_exposure variable
	
	replace ref_exposure=4 if ref_exposure>4 & ref_exposure<.

	** investigating exposure to refugee students

	replace refshare=refshare*100
	reg biat_ethnic c.refshare csize baseline_tmale i.ref_exposure baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured  btsurvey_16_refprop btraven_sd bteyes_sd b_gms b_pedagogy b_modern b_extrinsic b_warmth b_competence b_idealism i.bexper i.urfa i.grade1 i.b_schoolid if sample1==1 | sample0==1 , cluster(b_classid)

	lincom _b[1.ref_exposure]+_b[_cons]
	lincom _b[2.ref_exposure]+_b[_cons]
	lincom _b[3.ref_exposure]+_b[_cons]
	lincom _b[4.ref_exposure]+_b[_cons]


	frames reset
	frame create rsCI exposure r rlb rub

		lincom _b[_cons]
		frame post rsCI (1) (`r(estimate)') (`r(lb)') (`r(ub)')
	forvalues a = 1/4 {
		lincom _b[`a'.ref_exposure]+_b[_cons]
		frame post rsCI (`a'+1) (`r(estimate)') (`r(lb)') (`r(ub)')
	}

	frame change rsCI
	isid exposure, sort
	format r %3.2f
	format rlb %3.2f
	format rub %3.2f
	list, noobs clean

	graph twoway (connect r exposure , sort) (rcap rlb rub exposure) , scheme(s2mono) xlabel(1 "None" 2 "1-Term" 3 "2-Terms" 4 "3-Terms" 5 "4 or more -Terms") xscale(range (0.7 5.3) titlegap(3)) ylabel(-6 (2) 6, grid gmin gmax)  yscale(titlegap(2)) legend(off) ylab(, format(%8.0g))  xtitle("Duration of Exposure to Refugee Students (Period)") ytitle("Teacher's Ethnic Bias (Standardized)") graphregion(color(white))  bgcolor(white)  name(tethnic_exposure, replace)  caption("Kolmogorov-Smirnov test P-value, (None = 1-Term): `p1', (1-Term = 2-Terms): `p2'," "(2-Terms = 3-Terms): `p3', (3-Terms = 4 or more-Terms): `p4'", size(small))
	graph export "$path1/figure1.png", replace 

	** bring back the data	
	
	u `teacher_data', clear

